'use strict'
const whiteList = require('../lib/whiteList')
const friendService= require('../services').friendService
const friendController = {}

friendController.getFriend = async (ctx, next) => {
    ctx.result = await friendService.getFriend()
    return next()
}

// 创建分类
friendController.insertFriend = async (ctx, next) => {
    whiteList.needAdmin(ctx, next)
    const friendList = ctx.request.body
    ctx.result = await friendService.insertFriend(friendList)
    return next()
}

// 删除分类
friendController.deleteFriend = async (ctx, next) => {
    whiteList.needAdmin(ctx, next)
    const friendList = ctx.request.body
    ctx.result = await friendService.deleteFriend(friendList)
    return next()
}

// 编辑一个分类
friendController.updateOneFriend = async (ctx, next) => {
    whiteList.needAdmin(ctx, next)
    const friend = ctx.request.body
    ctx.result = await friendService.updateOneFriend(friend._id, friend)
    return next()
}

module.exports = friendController
